package com.example.tnot.Teacher.MinePart.container;

import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.tnot.R;
import com.example.tnot.Teacher.ActivityConfig.HasNavController;
import com.example.tnot.Teacher.ActivityConfig.TeacherHomeActivity;
import com.example.tnot.Teacher.MinePart.adapter.myadapter_tool;
import com.example.tnot.Teacher.MinePart.itembean.rv_SetListItem;

import java.util.ArrayList;
import java.util.List;

public class mineContainerFragment extends Fragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    private String mParam1;
    private String mParam2;

    private RecyclerView rv_MainPager;
    private LinearLayout ll_personal;
    private LinearLayout ll_class_info,ll_course,ll_attendance,ll_group;
    private List<rv_SetListItem> data;
    private TextView tv_clock;
    private TextView tv_attend;
    private NavController navController;
    View view;

    public mineContainerFragment() {
    }
    public static mineContainerFragment newInstance(String param1, String param2) {
        mineContainerFragment fragment = new mineContainerFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }

    }
    @Override
    public void onResume() {
        super.onResume();
        // 确保当前Fragment显示时底部导航栏是可见的
        if (getActivity() instanceof TeacherHomeActivity) {
            ((TeacherHomeActivity) getActivity()).showBottomNavigation();
            ((TeacherHomeActivity) getActivity()).enableViewPagerSwipe();
        }
    }

    @SuppressLint("MissingInflatedId")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.mine_container_fragment, container, false);
        InitViews();
        setListener();
        initdata();


        rv_MainPager.setLayoutManager(new LinearLayoutManager(getActivity()));

        myadapter_tool myadapter_tool = new myadapter_tool(data);
        rv_MainPager.setAdapter(myadapter_tool);

        //添加默认分割线
        DividerItemDecoration divider = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
        rv_MainPager.addItemDecoration(divider);


        return view;
    }
    private void InitViews() {
        rv_MainPager = view.findViewById(R.id.rv_mine);
        ll_personal = view.findViewById(R.id.PersonalInformation);
        ll_class_info = view.findViewById(R.id.ll_class_info);
        ll_course = view.findViewById(R.id.ll_course);
        ll_attendance = view.findViewById(R.id.ll_attendance);
        ll_group = view.findViewById(R.id.ll_group);
    }

    private void initdata() {
        data = new ArrayList<>();
        data.add(new rv_SetListItem("学生紧急联系",R.drawable.mine_student));
        data.add(new rv_SetListItem("成绩分析",R.drawable.mine_analysis));
//        data.add(new rv_SetListItem("排行榜",R.drawable.mine_range));
        data.add(new rv_SetListItem("笔记本",R.drawable.mine_notebook));
        data.add(new rv_SetListItem("所有文件",R.drawable.mine_file));
        data.add(new rv_SetListItem("我的收藏",R.drawable.mine_collect));
        data.add(new rv_SetListItem("隐私政策",R.drawable.privacy));
        data.add(new rv_SetListItem("设置",R.drawable.mine_set));
    }
    private void setListener() {
        ll_personal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //隐藏导航栏
                if (getActivity() instanceof TeacherHomeActivity) {
                    ((TeacherHomeActivity) getActivity()).hideBottomNavigation();
                    // 禁用ViewPager2的滑动
                    ((TeacherHomeActivity) getActivity()).disableViewPagerSwipe();
                }
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_mineFragment_to_personalFragment);
            }
        });


        ll_class_info.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_mineFragment_to_classInforFragment);
            }
        });
        ll_course.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
//                navController.navigate(R.id.action_mineFragment_to_assignmentHomeworkFragment);
            }
        });

        ll_attendance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_mineFragment_to_attandRateFragment);
            }
        });

        ll_group.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_mineFragment_to_myGroupFragment);
            }
        });
    }

    public  NavController getNavController() {
        return navController;
    }
}